<template>
	<view class="uni-pages">
		<view style="overflow: auto; -webkit-overflow-scrolling: touch;flex:1" v-if="showFlag">
			<web-view :webview-styles="webviewStyles" :style="{width:'100vw',}" :src="webviewUrl"
				@onPostMessage="handleMessage" @message="handleMessage"></web-view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showFlag:false,
				webviewStyles: {
					top: 0,
					height: null
				},
				webviewUrl: "",
				title: "",
				url: ""
			};
		},
		onLoad(option) {
			uni.setNavigationBarTitle({
				title: "课程详情"
			});
			// #ifdef APP-PLUS | MP-WEIXIN
			let platform = uni.getSystemInfoSync().platform;
			console.log(platform, '---------platform');
			if (platform !== 'ios') {
				this.getSystemInfo()
			}
			// #endif
			let env = this.getEnv()
			let WebviewBaseUrl = "https://ysxh.cnslpa.com/pdf-view/#/"
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('pdfData', (data)=> {
			    console.log(data)
				let obj = JSON.stringify({
					pdfUrl:data.pdfUrl,
					gotoNumber:data.gotoNumber
				})
				this.webviewUrl = `${WebviewBaseUrl}?obj=${obj}&env=${env}&timestamp=${new Date().getTime()}`;
				this.showFlag = true;
				console.log(this.webviewUrl)
				
			})
			  
			
			
		},
		methods: {
			// 获取屏幕信息
			getSystemInfo() {
				uni.getSystemInfo({
					success: ({
						screenHeight,
						statusBarHeight
					}) => {
						this.webviewStyles.top = statusBarHeight
						this.webviewStyles.height = screenHeight - statusBarHeight
					}
				});
			},
			getEnv() {
				// #ifdef MP-WEIXIN
				return 'MP-WEIXIN'
				// #endif
				// #ifdef APP-PLUS
				return 'APP-PLUS'
				// #endif
				// #ifdef H5
				return 'H5'
				// #endif
			},
			handleMessage(e) {
				console.log("接收到消息：" + JSON.stringify(e));
				const eventChannel = this.getOpenerEventChannel();
				eventChannel.emit('handleMessage', e);
			}
		},
		onReady() {
			this.webviewStyles.height = uni.getSystemInfoSync().windowHeight + 'px';
		}
	}
</script>

<style lang="scss" scoped>
	@import url("@/common/uni.scss");
</style>